package com.eol.common.jwt;

import lombok.extern.slf4j.Slf4j;
import com.eol.common.config.SystemPropertiesConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 2019/10/30
 * Time: 6:53 PM
 * Description: ApplicationStartUp
 */
@Slf4j
@Configuration
public class JwtAppStartConfig {

    @Resource
    private RsaKeyHelper rsaKeyHelper;

    @Resource
    private SystemPropertiesConfig systemPropertiesConfig;

    @Bean
    public PrivateKey createPrivateKey() throws Exception {
        return rsaKeyHelper.getPrivateKey(systemPropertiesConfig.getJwt().getPriKeyPath());
    }

    @Bean
    public PublicKey createPublicKey() throws Exception {
        return rsaKeyHelper.getPublicKey(systemPropertiesConfig.getJwt().getPubKeyPath());
    }
}
